import QtQuick
import QtQuick.Controls

Window {
    width: 640
    height: 480
    visible: true
    title: qsTr("Hello World")

    property var selectedItems: []

    ListView {
        id: listView
        anchors.fill: parent
        model: ["Item 1", "Item 2", "Item 3", "Item 4", "Item 5"]

        delegate: CheckDelegate {
            text: modelData
            width: listView.width

            onCheckedChanged: {
                if (checked) {
                    selectedItems.push(modelData)
                } else {
                    selectedItems = selectedItems.filter(item => item !== modelData)
                }
            }
        }
    }

    Button {
        text: "Get Selected Items"
        anchors.bottom: listView.bottom
        anchors.horizontalCenter: parent.horizontalCenter
        onClicked: {
            console.log("Selected items:", selectedItems)
        }
    }
}
